<?php

namespace App\Admin\Controllers;

use App\Models\Image;
use Encore\Admin\Controllers\AdminController as Controller;
use App\Models\Carousel;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;

class CarouselController extends Controller
{
    protected $title = "轮播管理";

    protected function grid()
    {
        $grid = new Grid(new Carousel);

        $grid->id('ID');
        $grid->title('标题');
        $grid->type('跳转类型')->display(function ($v) {
            return Carousel::CAROUSEL_TYPE[$v] ?? "未知类型";
        });
        $grid->type_id('类型ID');
        $grid->status('是否展示')->switch(Carousel::CAROUSEL_STATUS);

        $grid->actions(function ($actions) {
            $actions->disableDelete();
            $actions->disableView();
        });

        return $grid;
    }

    protected function form()
    {
        $form = new Form(new Carousel);

        $form->text('title', '标题');

        $form->image('cover.path', '封面');
        $form->hidden('cover.type')->value(Image::CAROUSEL);
        $form->select('type', '跳转类型')
            ->options(Carousel::CAROUSEL_TYPE)
            ->load('type_id', route('admin.api.carousel.type'));
        $form->select('type_id', '类型ID');
        $form->switch('status', '是否展示')->states(Carousel::CAROUSEL_STATUS);

        return $form;
    }
}
